<form action="<?php echo url_for('content/index')?>" method="GET">
<fieldset>
<legend>Шүүлт хийх</legend>
    <?php 
    $parentId = 0;
    $categories = Doctrine::getTable('Category')->findByParentId('content', 0);
    foreach ($categories as $category)
    {
      echo link_to($category, 'content/index?type='.$category->getTypeOld(), array()).' &nbsp; - &nbsp;'; 
      if($category->getTypeOld() == $sf_params->get('type')) $parentId = $category->getId();
    }?>
    
    <br clear="all">
    <br clear="all">

    Ангилал : &nbsp;&nbsp;&nbsp;
    <?php $categories = Doctrine::getTable('Category')->findByParentId('content', $parentId);?>
    <select id="categoryId" name="categoryId" style="width:274px;">
      <?php $selected = $sf_params->get('categoryId');?>
      <option style="padding-left:2px;" value="0" <?php if($selected==0) echo "selected"?>>&nbsp;- - - </option>
  	  <?php foreach ($categories as $category){
        listChildNodesInSelect($category, $selected, 0);
  	  }?>
  	</select>
  	
  	<?php function listChildNodesInSelect($p, $selected, $level){?>
      <option style="padding-left:2px;" value="<?php echo $p->getId()?>" <?php if($selected == $p->getId()) echo "selected"?>>
        <?php echo str_repeat(' &nbsp; &nbsp; &nbsp; ', $level).' &raquo; '.$p->getName();?>
      </option>
  
      <?php
        $childs = Doctrine::getTable('Category')->findByParentId('content', $p->getId());
    	  if (sizeof($childs)) {
    		  foreach  ($childs as $child){
       	    listChildNodesInSelect($child, $selected, $level+1);
          }
        }
      ?>
    <?php }?>
    
    <br clear="all">
    
    
    Түлхүүр үг : <input type="text" name="keyword" id="keyword" value="<?php echo $sf_request->getParameter('keyword')?>" size="50" />
    <input type="submit" value="Xайx &raquo;" />
    
    <br clear="all">
    <br clear="all">
    
    <?php $all = $sf_params->get('type') ? 'Бүх '.myConstants::getActivityTypeLowerValue($sf_params->get('type')) : 'Бүгд'?>
    <?php echo link_to($all, 'content/index')?> &nbsp; - &nbsp;
    <?php echo link_to('<span style="background:#ccffee;padding:0px 5px;">Нүүр хуудсанд харагдаж байгаа</span>', 'content/index?isOnhome=1&type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword)?> &nbsp; - &nbsp;
    <?php echo link_to('<span style="background:#ffff88;padding:0px 5px;">Онцлох</span>', 'content/index?isFeatured=1&type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword)?> &nbsp; - &nbsp;
    <?php echo link_to('<span style="background:#ccc;padding:0px 5px;">Идэвхигүй</span>', 'content/index?isActive=0&type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword)?> &nbsp; - &nbsp;
    <?php echo link_to('Идэвхитэй', 'content/index?isActive=1&type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword)?>

</fieldset>
</form>

<?php echo pager($pager, 'content/index?type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword.'&isActive='.$isActive.'&isFeatured='.$isFeatured)?>
<table width="100%">
  <thead>
    <tr>
      <th>Төрөл</th>
      <th>Ангилал</th>      
      <th>Гарчиг</th>
      <th>Оруулсан</th>
      <th>Огноо</th>
      <th>#</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($pager->getResults() as $content): ?>
    <tr style="background:<?php echo $content->getColor()?>;">
      <td><?php echo myConstants::getActivityTypeValue($content->getType()) ?></td>
      <td><?php echo $content->getCategory() ?></td>
      <td>
        <b><?php echo link_to($content, $content->getUri(), array('target'=>'_blank')) ?></b><br>
        <?php echo myTools::utf8_substr(strip_tags($content->getBody()), 0, 100) ?> ...
      </td>
      <td nowrap>
        <?php 
          $owner = $content->getOwner();
          if(($owner instanceof User) || ($owner instanceof Company))
          {
            if($owner instanceof User) $image = $owner->getFile();
            elseif($owner instanceof Company) $image = $owner->renderLogo();
            echo image_tag($image, array('style'=>"max-width:60px;max-height:60px;border:1px solid #ccc;padding:1px;")).'<br>';
            echo $owner;
          }
        ?>
        
        <br clear="all">
        
        <?php if($poster = Doctrine::getTable('Poster')->getPoster('content', $content->getId())):?>
          <!--POSTER-->
          <ul class="owner-contact" style="list-style-type:none;">
            <?php echo $poster->getName() ? '<li>'.image_tag('icons/circle-user.png', array('align'=>'absmiddle')).' '.$poster->getName().'</li>' : '' ?>
            <?php echo $poster->getPhone() ? '<li>'.image_tag('icons/circle-phone.png', array('align'=>'absmiddle')).' '.$poster->getPhone().'</li>': '' ?>
            <?php echo $poster->getFax() ? '<li>'.image_tag('icons/circle-fax.png', array('align'=>'absmiddle')).' '.$poster->getFax().'</li>' : '' ?>
            <?php echo $poster->getEmail() ? '<li>'.image_tag('icons/circle-email.png', array('align'=>'absmiddle')).' '.$poster->getEmail().'</li>' : '' ?>
            <?php if($web = $poster->getWeb()){
              $web = (preg_match("/^(http|https|ftp):\/\//i", $web)) ? $web : 'http://'.$web;
              echo '<li>'.image_tag('icons/circle-web.png', array('align'=>'absmiddle')).' &nbsp;'.link_to(myTools::utf8_substr($web, 0, 25), $web, array('target'=>'_blank')).'..</li>';
            }?>
            <?php //echo $poster->getIp() ? '<li>'.image_tag('icons/circle-paste.png', array('align'=>'absmiddle')).' '.$poster->getIp().'</li>' : '' ?>
            <?php echo $poster->getAddress() ? '<li>'.image_tag('icons/circle-address.png', array('align'=>'absmiddle')).' '.myTools::utf8_substr($poster->getAddress(), 0, 30).' ..</li>' : '' ?>
          </ul>
        <?php endif?>
      </td>
      <td nowrap>
        <b>Нэмэгдсэн:</b> <?php echo $content->getCreatedAt() ?><br>
        <b>Засварласан:</b> <?php echo $content->getUpdatedAt()?>
      </td>
      <td nowrap>
        <?php if($content->getIsActive()==1):?>
          <a href="<?php echo url_for('content/active?id='.$content->getId().'&status=0') ?>">Идэвхгүй болгох</a><br>
        <?php else:?>
          <a href="<?php echo url_for('content/active?id='.$content->getId().'&status=1') ?>">Идэвхжүүлэх</a><br>
        <?php endif;?>
        <?php if($content->getIsOnhome()==1):?>
          <a href="<?php echo url_for('content/makeOnhome?id='.$content->getId().'&status=0') ?>">Нүүр хуудаснаас авах</a><br>
        <?php else:?>
          <a href="<?php echo url_for('content/makeOnhome?id='.$content->getId().'&status=1') ?>">Нүүр хуудсанд гаргах</a><br>
        <?php endif;?>
        <?php if($content->getIsFeatured()==1):?>
          <a href="<?php echo url_for('content/featured?id='.$content->getId().'&status=0') ?>">Онцлох биш болгох</a><br>
        <?php else:?>
          <a href="<?php echo url_for('content/featured?id='.$content->getId().'&status=1') ?>">Онцлох болгох</a><br>
        <?php endif;?>
         <a onclick="return confirm('Та итгэлтэй байна уу?')" href="<?php echo url_for('content/delete?id='.$content->getId()) ?>">Устгах<?php //echo image_tag('icons/delete.gif', array()) ?></a>
      </td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>
<?php echo pager($pager, 'content/index?type='.$type.'&categoryId='.$categoryId.'&keyword='.$keyword.'&isActive='.$isActive.'&isFeatured='.$isFeatured)?>